<?php
/**
 * This file is part of the Yacms (http://www.yacms.org)
 * Copyright (c) 2019 gylr0505 (http://www.yacms.org)
 *
 * Author: 鬼一浪人 <gylr0505@163.com>
 *
 * DateTime: 19-10-24 下午8:39
 * Description:  模板消息对象模板生产者管理对象
 */
 
declare(strict_types = 1);

namespace App\Template\Queue;

use App\Template\TemplateProvider;

class Producer extends Manager
{
    /**
     * 发起客户端通知
     */
    private function batchNotify()
    {
        $provider = new TemplateProvider();
        foreach ($this->objects as $params) {
            $provider->generatorTemplate($params['id'],$params['type'])
              &&
            $provider->getTemplate()->accept($params)
              &&
            $provider->getTemplate()->notifyClient($params);
        }
        $provider = null;
        $this->objects  = null;
    }

    /**
     * @param callable|null $call
     */
    public function __invoke(callable  $call = null)
    {
        $this->batchNotify();
        $call();
    }
}